from django.contrib.auth.hashers import make_password
from rest_framework import serializers

from userapp.models import *


class UserSer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

    def create(self, validated_data):
        # 调用django提供的密码加密方法
        validated_data['password'] = make_password(validated_data['password'])      #验证数据使密码进行加密
        isinstance=User.objects.create(**validated_data)
        return isinstance
